home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / Messaging.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  2.8 KB  |  117 lines

  1. //-----------------------------------------------------------------------------
  2. //
  3. // $LogFile$
  4. // $Revision: 1.1.2.1 $
  5. // $Author: ttimo $
  6. // $Date: 2000/02/04 22:59:34 $
  7. // $Log: Messaging.cpp,v $
  8. // Revision 1.1.2.1  2000/02/04 22:59:34  ttimo
  9. // messaging API preview
  10. //
  11. //
  12. // DESCRIPTION:
  13. // implementation of IMessaging specific interface
  14. // 
  15.  
  16. #include "stdafx.h"
  17.  
  18. CPtrArray l_Listeners[RADIANT_MSGCOUNT];
  19. CPtrArray l_WindowListeners;
  20. CXYWndWrapper l_XYWndWrapper;
  21.  
  22. void WINAPI QERApp_HookWindow(IWindowListener* pListen)
  23. {
  24.     l_WindowListeners.Add( pListen );
  25.     pListen->IncRef();
  26. }
  27.  
  28. void WINAPI QERApp_UnHookWindow(IWindowListener* pListen)
  29. {
  30.     for ( int i = 0; i < l_WindowListeners.GetSize(); i++ )
  31.     {
  32.         if (l_WindowListeners.GetAt(i) == pListen)
  33.         {
  34.             l_WindowListeners.RemoveAt(i);
  35.             pListen->DecRef();
  36.             return;
  37.         }
  38.     }
  39. #ifdef _DEBUG
  40.     Sys_Printf("WARNING: IWindowListener not found in QERApp_UnHookWindow\n");
  41. #endif
  42. }
  43.  
  44. void DispatchOnMouseMove(UINT nFlags, int x, int y)
  45. {
  46.     for( int i = 0; i < l_WindowListeners.GetSize(); i++ )
  47.         static_cast<IWindowListener*>(l_WindowListeners.GetAt(i))->OnMouseMove( nFlags, x, y );
  48. }
  49.  
  50. bool DispatchOnLButtonDown(UINT nFlags, int x, int y)
  51. {
  52.     for( int i = 0; i < l_WindowListeners.GetSize(); i++ )
  53.         if (static_cast<IWindowListener*>(l_WindowListeners.GetAt(i))->OnLButtonDown( nFlags, x, y ))
  54.             return true;
  55.     return false;
  56. }
  57.  
  58. bool DispatchOnLButtonUp(UINT nFlags, int x, int y)
  59. {
  60.     for( int i = 0; i < l_WindowListeners.GetSize(); i++ )
  61.         if (static_cast<IWindowListener*>(l_WindowListeners.GetAt(i))->OnLButtonUp( nFlags, x, y ))
  62.             return true;
  63.     return false;
  64. }
  65.  
  66. void WINAPI QERApp_HookListener(IListener* pListen, int Msg)
  67. {
  68. #ifdef _DEBUG
  69.     if (Msg >= RADIANT_MSGCOUNT)
  70.     {
  71.         Sys_Printf("ERROR: bad index in QERApp_HookListener\n");
  72.         return;
  73.     }
  74. #endif
  75.     l_Listeners[Msg].Add( pListen );
  76.     pListen->IncRef();
  77. }
  78.  
  79. int  WINAPI QERApp_UnHookListener(IListener* pListen)
  80. {
  81.     int count = 0;
  82.     for( int i = 0; i<RADIANT_MSGCOUNT; i++ )
  83.         for( int j = 0; j<l_Listeners[i].GetSize(); j++ )
  84.             if (l_Listeners[i].GetAt(j) == pListen)
  85.             {
  86.                 l_Listeners[i].RemoveAt(j);
  87.                 pListen->DecRef();
  88.                 count++;
  89.             }
  90.     return count;
  91. }
  92.  
  93. void DispatchRadiantMsg( int Msg )
  94. {
  95. #ifdef _DEBUG
  96.     if (Msg >= RADIANT_MSGCOUNT)
  97.     {
  98.         Sys_Printf("ERROR: bad index in DispatchRadiantMsg\n");
  99.         return;
  100.     }
  101. #endif
  102.     for(int i = 0; i<l_Listeners[Msg].GetSize(); i++)
  103.         static_cast<IListener *>(l_Listeners[Msg].GetAt(i))->DispatchRadiantMsg(Msg);
  104. }
  105.  
  106. void CXYWndWrapper::SnapToGrid( int x1, int y1, vec3_t pt )
  107. {
  108.     CRect rctZ;
  109.     g_pParentWnd->ActiveXY()->GetClientRect( rctZ );
  110.     g_pParentWnd->ActiveXY()->SnapToPoint( x1, rctZ.Height() - 1 - y1, pt );
  111. }
  112.  
  113. IXYWndWrapper* WINAPI QERApp_GetXYWndWrapper()
  114. {
  115.     return &l_XYWndWrapper;
  116. }
  117.